<html>
<head><meta charset="utf-8"><title>exhaustiveness checking · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html">exhaustiveness checking</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="131124595"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131124595" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131124595">(Aug 08 2018 at 18:21)</a>:</h4>
<p>So <span class="user-mention" data-user-id="120791">@RalfJ</span> and I had a good chat about exhaustiveness checking and uninhabited types and how to think about it today. <span class="user-mention" data-user-id="120791">@RalfJ</span> I was wondering, I know you've been going crazy with the blog posts lately, were you planning on trying to write that up?</p>



<a name="131131259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131131259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131131259">(Aug 08 2018 at 20:34)</a>:</h4>
<p>Huzzah!  I was sad that RFC got postponed...</p>



<a name="131136999"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131136999" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131136999">(Aug 08 2018 at 22:44)</a>:</h4>
<p>TBH I thought I would end my blog post streak for now and get back to getting some work done ;)</p>



<a name="131137016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131137016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131137016">(Aug 08 2018 at 22:45)</a>:</h4>
<p>Also isnt this closer to an RFC already?^^</p>



<a name="131137894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131137894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131137894">(Aug 08 2018 at 23:08)</a>:</h4>
<p>heh :) ok -- I might be up to try writing it out</p>



<a name="131221285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131221285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131221285">(Aug 10 2018 at 07:19)</a>:</h4>
<p>Thanks! Let me know if I should write some part of that.</p>



<a name="131228352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131228352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131228352">(Aug 10 2018 at 10:01)</a>:</h4>
<p>I started a post, here is a draft, but I am not happy with it:</p>
<p><a href="https://gist.github.com/nikomatsakis/b1d007abeb57b8f3eb35cd9b51e98dbc" target="_blank" title="https://gist.github.com/nikomatsakis/b1d007abeb57b8f3eb35cd9b51e98dbc">https://gist.github.com/nikomatsakis/b1d007abeb57b8f3eb35cd9b51e98dbc</a></p>



<a name="131228353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131228353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131228353">(Aug 10 2018 at 10:01)</a>:</h4>
<p>for one thing, I spent most of the time so far introducing the problems etc</p>



<a name="131228394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131228394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131228394">(Aug 10 2018 at 10:02)</a>:</h4>
<p>I think I might start over and just cut to the chase, then come back and talk a bit about the tensions :)</p>



<a name="131228751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131228751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131228751">(Aug 10 2018 at 10:12)</a>:</h4>
<p>and I suppose I should think about drafting something for the UCG repo</p>



<a name="131956064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131956064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131956064">(Aug 11 2018 at 13:53)</a>:</h4>
<p>Oh wow that's a long post you wrote^^</p>



<a name="131956070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131956070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131956070">(Aug 11 2018 at 13:53)</a>:</h4>
<p>TBH I would probably start with the <code>!</code> pattern</p>



<a name="131956110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131956110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131956110">(Aug 11 2018 at 13:54)</a>:</h4>
<p>and the fact that it does not require code to follow the pattern, because it is expressing some kind of "proof" that this case cannot happen</p>



<a name="131956129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131956129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131956129">(Aug 11 2018 at 13:55)</a>:</h4>
<p>which then leads us to auto-generating that pattern -- feasible only because no code must be generated</p>



<a name="131956133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131956133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131956133">(Aug 11 2018 at 13:55)</a>:</h4>
<p>and then the problems of doing so when <code>&amp;</code> is involved</p>



<a name="131956246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131956246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131956246">(Aug 11 2018 at 13:59)</a>:</h4>
<p>I think by now we have so much code that handles <code>&amp;T</code> where the memory is not fully initialized, we cannot reasonably make that requirement. Someone posted an example where this might be useful in the internals thread for my model, I still need to look at that in more detail.<br>
But my gut feeling right now is that having a <code>&amp;!</code> is not insta-UB. that is, however, not in contradiction with auto-never'ing it; that would just give us UB more selectively and for a different reason (namely, the <code>!</code> pattern that the user did not write).</p>



<a name="131958457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/131958457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nicole Mazzuca <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#131958457">(Aug 11 2018 at 15:05)</a>:</h4>
<p>yeah, I think looking at <a href="https://github.com/rust-lang/rfcs/pull/1892#issuecomment-412278317" target="_blank" title="https://github.com/rust-lang/rfcs/pull/1892#issuecomment-412278317">https://github.com/rust-lang/rfcs/pull/1892#issuecomment-412278317</a>, it's entirely reasonable that the guarantees of <code>&amp;mut T</code> (and <code>&amp;T</code>), at a compiler level, should be <code>object with read-[write] capabilities of size_of_val(r)</code>. I don't think it's reasonable to change this at this point.</p>



<a name="132007886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132007886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132007886">(Aug 12 2018 at 19:11)</a>:</h4>
<p>I think that requiring <code>&amp;T</code> point to a valid value always also goes against the desire to make a reference aliasing model that allows <code>split_at_mut</code> to work, as well?</p>



<a name="132007888"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132007888" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132007888">(Aug 12 2018 at 19:11)</a>:</h4>
<p>Since that implies that an invariant that's currently directly on the reference types is instead going to be about accesses and uses.</p>



<a name="132059352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132059352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132059352">(Aug 13 2018 at 17:05)</a>:</h4>
<blockquote>
<p>and the fact that it does not require code to follow the pattern, because it is expressing some kind of "proof" that this case cannot happen</p>
</blockquote>
<p>yes, I need to rework it</p>



<a name="132059493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132059493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132059493">(Aug 13 2018 at 17:08)</a>:</h4>
<blockquote>
<p>But my gut feeling right now is that having a <code>&amp;!</code> is not insta-UB. that is, however, not in contradiction with auto-never'ing it; that would just give us UB more selectively and for a different reason (namely, the <code>!</code> pattern that the user did not write).</p>
</blockquote>
<p>the key thing for me was that auto-never could treat <code>&amp;!</code> as "effectively uninhabited", but that we could lint against this "in or around" unsafe code, since we now have a way to explicitly talk about it as well. Not sure if that's a good idea or not, but it's at least a possibility for a "third way"</p>



<a name="132059497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132059497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132059497">(Aug 13 2018 at 17:08)</a>:</h4>
<p><span class="user-mention" data-user-id="123893">@alercah</span> I don't think I fully understand what you're saying</p>



<a name="132063013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132063013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132063013">(Aug 13 2018 at 18:17)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> ok take a look at this <a href="https://gist.github.com/nikomatsakis/b1d007abeb57b8f3eb35cd9b51e98dbc#file-exhaustiveness-take-2-md" target="_blank" title="https://gist.github.com/nikomatsakis/b1d007abeb57b8f3eb35cd9b51e98dbc#file-exhaustiveness-take-2-md">new version of the post</a></p>



<a name="132063015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132063015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132063015">(Aug 13 2018 at 18:17)</a>:</h4>
<p>(and anyone else)</p>



<a name="132063205"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132063205" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132063205">(Aug 13 2018 at 18:20)</a>:</h4>
<blockquote>
<p>I think that requiring <code>&amp;T</code> point to a valid value always also goes against the desire to make a reference aliasing model that allows <code>split_at_mut</code> to work, as well?</p>
</blockquote>
<p>I do not see the contradiction here. Both the input and the output of <code>split_and_mut</code> always point to properly initialized data.</p>



<a name="132063584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132063584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132063584">(Aug 13 2018 at 18:27)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> that looks great!</p>



<a name="132063586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132063586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132063586">(Aug 13 2018 at 18:27)</a>:</h4>
<p>I like it.</p>



<a name="132063807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132063807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132063807">(Aug 13 2018 at 18:30)</a>:</h4>
<p>I think you promised that the unsafe section would come back to why products only auto-never when all fields do, but the unsafe section does not say anything about that</p>



<a name="132064063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064063">(Aug 13 2018 at 18:35)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> oh, right, I cut that</p>



<a name="132064066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064066">(Aug 13 2018 at 18:35)</a>:</h4>
<p>I can maybe add back a bit</p>



<a name="132064073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064073">(Aug 13 2018 at 18:35)</a>:</h4>
<p>yeah I think that'd be good</p>



<a name="132064076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064076">(Aug 13 2018 at 18:35)</a>:</h4>
<p>it seems non-obvious</p>



<a name="132064117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064117">(Aug 13 2018 at 18:36)</a>:</h4>
<p>in fact I am not even very clear why we do it :D</p>



<a name="132064128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064128">(Aug 13 2018 at 18:36)</a>:</h4>
<p>it has to do with uninitialized data</p>



<a name="132064130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064130">(Aug 13 2018 at 18:36)</a>:</h4>
<p>in particular, otherwise,</p>



<a name="132064134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064134">(Aug 13 2018 at 18:36)</a>:</h4>
<p>there would be valid patterns one could write</p>



<a name="132064145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064145">(Aug 13 2018 at 18:36)</a>:</h4>
<p>e.g., <code>match x.value { (y, _) =&gt; .. }</code> where <code>x: Uninit&lt;(u32,!)&gt;</code></p>



<a name="132064169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064169">(Aug 13 2018 at 18:37)</a>:</h4>
<p>I wanted the invariant that autonever nevers adds a pattern that <em>could have had</em> a body</p>



<a name="132064194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064194">(Aug 13 2018 at 18:37)</a>:</h4>
<p>ah. yes that makes sense.</p>



<a name="132064241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064241">(Aug 13 2018 at 18:38)</a>:</h4>
<p>reminds me of the failed optimizations to make any struct with an uninhabited field a ZST</p>



<a name="132064244"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064244" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064244">(Aug 13 2018 at 18:38)</a>:</h4>
<p>and then someone though of partial initialization :P</p>



<a name="132064269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064269">(Aug 13 2018 at 18:39)</a>:</h4>
<p>yes I think they are related :)</p>



<a name="132064277"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132064277" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132064277">(Aug 13 2018 at 18:39)</a>:</h4>
<p>I thought about citing that in the post but thought it'd be too much</p>



<a name="132068862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132068862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132068862">(Aug 13 2018 at 20:09)</a>:</h4>
<p>The <code>split_at_mut</code> thing is about trying to make a version that doesn't require you to destructure and rebuild the slice manually. That requires changing the rules so that multiple <code>&amp;mut</code> can coexist if they aren't used in a conflicting way, at least in some limited scope. This to me feels generally in the direction of making the requirements be about the actual use of a type.</p>



<a name="132068915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132068915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132068915">(Aug 13 2018 at 20:10)</a>:</h4>
<p>So if <code>&amp;!</code> was instantly UB, I feel that would be moving in the opposite direction.</p>



<a name="132071373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132071373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132071373">(Aug 13 2018 at 20:57)</a>:</h4>
<p><span class="user-mention" data-user-id="123893">@alercah</span> the multiple <code>&amp;mut</code> never coexist. One stops being used before the other is created.</p>



<a name="132071378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132071378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132071378">(Aug 13 2018 at 20:57)</a>:</h4>
<p>That's how my model allows <code>split_at_mut</code></p>



<a name="132071746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132071746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132071746">(Aug 13 2018 at 21:03)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I mean inside <code>split_at_mut</code>.</p>



<a name="132072251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132072251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132072251">(Aug 13 2018 at 21:12)</a>:</h4>
<p>Yes, that's what I was talking about.</p>



<a name="132072590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132072590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132072590">(Aug 13 2018 at 21:18)</a>:</h4>
<p>How would you write it, then?</p>



<a name="132073024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132073024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132073024">(Aug 13 2018 at 21:27)</a>:</h4>
<p>Just like it already is in libcore right now</p>



<a name="132073064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132073064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132073064">(Aug 13 2018 at 21:28)</a>:</h4>
<p>notice that <code>self</code> does not get used again</p>



<a name="132073385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132073385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132073385">(Aug 13 2018 at 21:34)</a>:</h4>
<p>but really we should have this discussion in the stacked-borrows topic :D</p>



<a name="132074263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132074263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132074263">(Aug 13 2018 at 21:55)</a>:</h4>
<p><a href="http://smallcultfollowing.com/babysteps/blog/2018/08/13/never-patterns-exhaustive-matching-and-uninhabited-types-oh-my/" target="_blank" title="http://smallcultfollowing.com/babysteps/blog/2018/08/13/never-patterns-exhaustive-matching-and-uninhabited-types-oh-my/">posted on my blog</a></p>



<a name="132074265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132074265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132074265">(Aug 13 2018 at 21:55)</a>:</h4>
<p>I should probably open an internals thread</p>



<a name="132074344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132074344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132074344">(Aug 13 2018 at 21:57)</a>:</h4>
<p>done: <a href="https://internals.rust-lang.org/t/blog-post-never-patterns-exhaustive-matching-and-uninhabited-types/8197" target="_blank" title="https://internals.rust-lang.org/t/blog-post-never-patterns-exhaustive-matching-and-uninhabited-types/8197">internals thread</a></p>



<a name="132076233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness%20checking/near/132076233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> alercah <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/exhaustiveness.20checking.html#132076233">(Aug 13 2018 at 22:43)</a>:</h4>
<p>I was thinking a hypothetical version that doesn't use <code>from_raw_parts_mut</code>, like Niko talked about in an older blog post.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>